home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 52
/
Amiga Format AFCD52 (Issue 136, May 2000).iso
/
-in_the_mag-
/
javascript
/
part5
/
scripts
/
lastnamecookie.js
< prev
next >
Wrap
Text File
|
2000-02-07
|
3KB
|
82 lines
<head>
<title>NameCookie2010</title>
</head>
<body>
<script language="JavaScript">
<!--
//This script was made by Giedrius gietam@eunet.lt
//It is a script which checks if your page's visitor visited your site first time,
//if so, it puts a cookie in your page's visitors computer
//with visitors name stored in it, then reads a name from that cookie
//and stores it into the variable called GuestName.
//If that visitor goes back to your site, script checks isn't his name a default(Nobody),
//it means hasn't he just pressed "OK" or "Cancel" button not worrying aboutthe name.
//If visitors name is a default name, then script asks again.
//Othervise it reads a GuestName from the cookie.
//You can send me credits,corrections or modifications of this script.
//I would be thankful.
//When you use this script, please leave the following lines:
//Script: NameCookie2010
//(c)Giedrius gietam@eunet.lt
//Corrections, modifications and suggestions are welcome.
cookie_name = "NameCookie2010";
var GuestName;
function putCookie() {
if(document.cookie) { index = document.cookie.indexOf(cookie_name);}
else { index = -1;}
if (index == -1)
{
GuestName=window.prompt("Hello! What's your name?","Nobody");
if (GuestName==null) GuestName="Nobody";
document.cookie=cookie_name+"="+GuestName+"; expires=Tuesday, 05-Apr-2010 05:00:00 GMT";
}
else
{
namestart = (document.cookie.indexOf("=", index) + 1);
nameend = document.cookie.indexOf(";", index);
if (nameend == -1) { nameend = document.cookie.length;}
GuestName = document.cookie.substring(namestart, nameend);
if (GuestName=="Nobody")
{
GuestName=window.prompt("Hello again!!!"+"\n"+"Last time you didn't tell me your name. Maybe you want to do it now?","Nobody");
if ((GuestName!="Nobody")&&(GuestName!=null))
{document.cookie=cookie_name+"="+GuestName+"; expires=Tuesday, 05-Apr-2010 05:00:00 GMT";}
if (GuestName==null) GuestName="Nobody";
}
}
}
function getName() {
if(document.cookie)
{
index = document.cookie.indexOf(cookie_name);
if (index != -1)
{
namestart = (document.cookie.indexOf("=", index) + 1);
nameend = document.cookie.indexOf(";", index);
if (nameend == -1) {nameend = document.cookie.length;}
GuestName = document.cookie.substring(namestart, nameend);
return GuestName;
}
}
}
putCookie();
GuestName=getName();
//-->
</script>
<P>
<script>
document.write("Hello, "+GuestName+", nice to meet you!!!");
</script>
<P>